package com.peycash.ws.endpoint;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import com.peycash.common.dto.NuevoClienteRequestDTO;
import com.peycash.common.dto.NuevoClienteResponseDTO;
import com.peycash.fachada.ClienteOpFachada;
import com.peycash.fachada.FachadaException;

@Service("registroServiceEndpoint")
@WebService(serviceName = "Registro")
public class ClienteOpEndpoint extends SpringBeanAutowiringSupport {

	@Autowired
	private ClienteOpFachada fachada;
	
	@WebMethod(operationName = "addCliente")
	public NuevoClienteResponseDTO addClienteEnvia(NuevoClienteRequestDTO request) {
		NuevoClienteResponseDTO response = new NuevoClienteResponseDTO();
		if(!fachada.validaEntrada(request)){
			response = fachada.creaResponseCamposIncompletos();
		}
		if(!fachada.validaFormatos(request)){
			response = fachada.creaResponseFormatoInvalido();
		}
		try {
			fachada.addToContext(request);
			response = fachada.creaResponseValido();
		} catch (FachadaException e) {
			response = fachada.creaResponseError();
		}
		return response;
	}

	/*
    @WebMethod(exclude=true)
	public void setFachada(ClienteOpFachada fachada) {
		this.fachada = fachada;
	}*/
}
